import 'dart:convert' show json;

import 'package:flutter_common_app/data/account_data.dart';
import 'package:flutter_common_app/data/profile_data.dart';
import 'package:flutter_common_app/data/protection.dart';

class UserInfoData {
  UserInfoData({
    this.loginType,
    this.code,
    this.account,
    this.token,
    this.profile,
    this.cookie,
  });

  factory UserInfoData.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    return UserInfoData(
      loginType: asT<int>(jsonRes['loginType']),
      code: asT<int>(jsonRes['code']),
      account: AccountData.fromJson(asT<Map<String, dynamic>>(jsonRes['account'])),
      token: asT<String>(jsonRes['token']),
      profile: ProfileData.fromJson(asT<Map<String, dynamic>>(jsonRes['profile'])),
      cookie: asT<String>(jsonRes['cookie']),
    );
  }

  int loginType;
  int code;
  AccountData account;
  String token;
  ProfileData profile;
  String cookie;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'loginType': loginType,
    'code': code,
    'account': account,
    'token': token,
    'profile': profile,
    'cookie': cookie,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}
